package com.csii.activiti.server.controller;

import cn.hutool.core.collection.CollUtil;
import com.csii.activiti.server.abstraction.entity.ActUser;
import com.csii.activiti.server.abstraction.entity.ActUserDetail;
import com.csii.activiti.server.abstraction.service.ActDeptService;
import com.csii.activiti.server.abstraction.service.ActRoleService;
import com.csii.activiti.server.abstraction.service.ActUserService;
import com.csii.activiti.server.abstraction.uilts.ActCurrentUserUtils;
import com.csii.activiti.server.api.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags="用户")
@RestController
@RequestMapping("/${activity.basic.url:activiti}/user")
public class UserController {

    @Autowired
    private ActUserService actUserService;

    @Autowired
    private ActRoleService actRoleService;

    @Autowired
    private ActDeptService actDeptService;


    @ApiOperation("登录")
    @GetMapping("/login")
    public Result<List<ActUser>> queryUserLikeUsernameOrNickname(@ApiParam(value = "username" ,required = true) @RequestParam String username){
        List<ActUser> actUsers = actUserService.queryUserByUsernames(CollUtil.newHashSet(username));
        if (CollUtil.isNotEmpty(actUsers)){
            ActUser actUser = actUsers.get(0);
            ActUserDetail actUserDetail = new ActUserDetail();
            actUserDetail.setUsername(actUser.getUsername());
            actUserDetail.setNickname(actUser.getNickname());
            ActCurrentUserUtils.setCurrentUserDetail(actUserDetail);
            return Result.ok("登录成功");
        }
        return Result.ok("登录失败");
    }


}
